import { ColumnProps, PaginationConfig } from "antd/lib/table";
import * as React from "react";
import { IColumn, VPS_STATUS } from "../../interfaces";
import { defaultState } from "../../store/reducer";
import Action_edit from "../action/edit";
import { formatTimeStamp10 } from "../../../../../common/tools/time_utils";
import { Tag } from "antd";

// 获取分页信息
export function getPaginationInfo(total: number): PaginationConfig {
  return {
    total,
    defaultCurrent: defaultState.table_filter.pageNum,
    defaultPageSize: defaultState.table_filter.pageSize,
    showSizeChanger: true, //是否可以改变pageSize
    showQuickJumper: true, //跳转
    showTotal: (total: number, _: any) => `共${total}条`,
    pageSizeOptions: ["10", "20", "50"], //每页条数选项,
    position: "bottom"
  };
}

export function columnsFun() {
  const columns: ColumnProps<IColumn>[] = [
    {
      title: "操作",
      key: "action",
      render: (_: any, record: IColumn) => (
        <span>
          <Action_edit record={record} />
        </span>
      )
    },
    {
      title: "ID",
      dataIndex: "id",
      key: "id",
      sorter: true
    },
    {
      title: "编号",
      dataIndex: "code",
      key: "code"
    },
    {
      title: "地区",
      dataIndex: "areaName",
      key: "areaName"
    },
    {
      title: "状态",
      key: "status",
      dataIndex: "status",
      render: (_text, record) => {
        let status = "";
        for (let i = 0; i < VPS_STATUS.length; i++) {
          if (record.status === VPS_STATUS[i].id) {
            status = VPS_STATUS[i].value;
          }
        }
        switch (record.status) {
          case 0: {
            return <Tag color="#87d068">{status}</Tag>;
          }
          case 2: {
            return <Tag color="#f50">{status}</Tag>;
          }
          default: {
            return <Tag>{status}</Tag>;
          }
        }
      }
    },
    {
      title: "IP和端口",
      key: "ipPort",
      render: (_text, record) => {
        return record.ip && record.port ? `${record.ip}:${record.port}` : "";
      }
    },
    {
      title: "远程登录",
      key: "loginIpPwd",
      render: (_text, record) => {
        return record.loginIp && record.loginPwd
          ? `${record.loginIp} 密码:${record.loginPwd}`
          : "";
      }
    },
    {
      title: "拨号账户密码",
      key: "dialUpUsernamePwd",
      render: (_text, record) => {
        return record.dialUpAccount && record.dialUpPwd
          ? `${record.dialUpAccount} 密码:${record.dialUpPwd}`
          : "";
      }
    },
    {
      title: "注册时间",
      key: "createdTime",
      dataIndex: "createdTime"
    },
    {
      title: "更新时间",
      key: "updatedTime",
      dataIndex: "updatedTime"
    },
    {
      title: "备注",
      key: "note",
      dataIndex: "note"
    }
  ];
  return columns;
}
